package de.jmda.sample.navigate;

import static de.jmda.core.mproc.ProcessingUtilities.getElementsAnnotatedWith;
import static de.jmda.core.mproc.ProcessingUtilities.isProcessingOver;
import static de.jmda.core.mproc.ProcessingUtilities.typeOfAsElement;

import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Set;

import javax.lang.model.element.Element;

import de.jmda.core.MarkerAnnotation;
import de.jmda.core.mproc.task.AbstractAnnotatedElementsTask;
import de.jmda.core.mproc.task.TaskException;
import de.jmda.core.mproc.task.TaskRunner;
import de.jmda.core.util.TypeUtil;
import de.jmda.core.util.FileUtil;
import de.jmda.core.util.fileset.FileSet;

class Aggregated {}

class Aggregation
{
	@MarkerAnnotation Aggregated aggregatedField;
//	@MarkerAnnotation int aggregatedField;
	
	public static void main(String[] args) throws IOException
  {
		Task task =
				new Task(
						TypeUtil.createAnnotationsSet(MarkerAnnotation.class),
						FileUtil.createFileSet(Aggregation.class, "src/main/java"));
		TaskRunner.run(task);;
  }

	static class Task extends AbstractAnnotatedElementsTask
	{
		public Task(
				Set<Class<? extends Annotation>> annotationTypes, FileSet fileset)
    {
	    super(annotationTypes, fileset);
    }

		@Override
	  public boolean execute() throws TaskException
	  {
			if (false == isProcessingOver())
			{
				Element aggregatedFieldAsElement =
						getElementsAnnotatedWith(MarkerAnnotation.class).iterator().next();
				
				System.out.println(
						aggregatedFieldAsElement.asType().toString() + " " +
						aggregatedFieldAsElement.getSimpleName());
				
				Element aggregatedAsElement = typeOfAsElement(aggregatedFieldAsElement);
				
				System.out.println(
						aggregatedAsElement.asType().toString() + " " +
						aggregatedAsElement.getSimpleName());
			}
	
			return false;
	  }
	}
}